"use strict";
// 类型保护机制
var Type;
(function (Type) {
    Type[Type["Strong"] = 0] = "Strong";
    Type[Type["Week"] = 1] = "Week";
})(Type || (Type = {}));
var Java = /** @class */ (function () {
    function Java() {
    }
    Java.prototype.helloJava = function () {
        console.log('hello Java');
    };
    return Java;
}());
var JavaScript = /** @class */ (function () {
    function JavaScript() {
    }
    JavaScript.prototype.helloJavaScript = function () {
        console.log('hello javascript');
    };
    return JavaScript;
}());
function isJava(lang) {
    return lang.helloJava !== undefined;
}
function getLanguage(type, x) {
    var lang = type === Type.Strong ? new Java() : new JavaScript();
    if (isJava(lang)) {
        lang.helloJava();
    }
    else {
        lang.javascript();
    }
    // if ((lang as Java).helloJava) {
    //   (lang as Java).helloJava()
    // } else {
    //   (lang as JavaScript).helloJavaScript()
    // }
    // instanceof方法
    // if (lang instanceof Java) {
    //   lang.helloJava()
    // } else {
    //   lang.helloJavaScript()
    // }
    // in
    // if ('java' in lang) {
    //   lang.helloJava()
    // } else {
    //   lang.helloJavaScript()
    // }
    //typeof
    // if (typeof x === 'string') {
    //   x.length
    // } else {
    //   x.toFixed(2)
    // }
    return lang;
}
var pet = {
    run: function () { },
    jump: function () { }
};
//联合类型
var Dog4 = /** @class */ (function () {
    function Dog4() {
    }
    Dog4.prototype.run = function () { };
    Dog4.prototype.eat = function () { };
    return Dog4;
}());
var Cat4 = /** @class */ (function () {
    function Cat4() {
    }
    Cat4.prototype.jump = function () { };
    Cat4.prototype.eat = function () { };
    return Cat4;
}());
var Master;
(function (Master) {
    Master[Master["Boy"] = 0] = "Boy";
    Master[Master["Girl"] = 1] = "Girl";
})(Master || (Master = {}));
function getPet(master) {
    var pet = master === Master.Boy ? new Dog4() : new Cat4();
    pet.eat();
    return pet;
}
function area(s) {
    switch (s.kind) {
        case 'square':
            return s.size = s.size;
        case 'rectangle':
            return s.height = s.width;
        case 'circle':
            return Math.PI * Math.pow(s.r, 2);
        default:
            return (function (e) { throw new Error(e); })(s);
    }
}
console.log(area({ kind: 'circle', r: 1 }));
//索引类型
var obj4 = {
    a: 1,
    b: 2,
    c: 3
};
function getValues(obj, keys) {
    return keys.map(function (key) { return obj[key]; });
}
console.log(getValues(obj4, ['a', 'b']));
var key;
var value;
